$(".cover-li").each(function(index,item){	 
	 $(item).hover(function(){
		 $(".cover").eq(index).css("display","block")
	 },function(){
		 $(".cover").eq(index).css("display","none")
	 })
 })
 var lang = 1;
 $(".add").click(function(){
	 lang++;
	 if(lang>=5){
		 lang = 5
	 }
	 $(".num").text(lang)
 })
 $(".minus").click(function(){
 	 lang--;
 	 if(lang<=1){
 		 lang = 1
 	 }
 	 $(".num").text(lang)
 })
 
 
 
 
 //鼠标移动在box上,显示cover
 
 var box = document.querySelector(".imgOrVideo")
 var cover = document.querySelector(".imgcover")
 var glass = document.querySelector(".glass")
 box.onmouseover = function() {
 var img = document.querySelector("img[_block='block']")
 	cover.style.display = "block";
 	glass.style.display = "block";
 	var _src=img.getAttribute("src")
 	glass.style.backgroundImage="url("+_src+")"
 }
 box.onmouseout = function() {
 	cover.style.display = "none"
 	glass.style.display = "none"
 }
 
 //鼠标在移动时跟随
 box.onmousemove = function(e) {
 	var boxHeight=parseInt(window.getComputedStyle(box).height);
 	var boxWidth=parseInt(window.getComputedStyle(box).width);
 	var coverHeight=parseInt(window.getComputedStyle(cover).height);
 	var coverWidth=parseInt(window.getComputedStyle(cover).width);
 	var _top = (e.pageY-box.offsetTop)-(coverHeight/2);
 	if(_top<0){
 		_top=0
 	}else if(_top>(boxHeight-coverHeight)){
 		_top=boxHeight-coverHeight
 	}
 	var _left = (e.pageX-box.offsetLeft)-(coverWidth/2);
 	if(_left<0){
 		_left=0
 	}else if(_left>(boxWidth-coverWidth)){
 		_left=boxWidth-coverWidth
 	}
 	cover.style.top = _top+'px';
 	cover.style.left = _left+'px';
 	
 	glass.style.backgroundPosition="-"+(_left*2.5)+"px -"+(_top*2.5)+"px";
 }
 
 $(".boxList>li").click(function(){
	 $(".num").text("1")
	 lang=1
	 Array.from($(".boxList>li")).forEach(function(item){
		 $(item).css("box-shadow", "0 0 0 1px #ddd");
		 $(item).removeAttr("_norm");
	 });
	 Array.from($(".imgg0")).forEach(function(item){
		 $(item).css("display", "none");
		 $(item).removeAttr("_block");
	 })
	 $(this).css("box-shadow", "inset 0 0 0 2px #000").attr("_norm","norm");
	 
	 $(".imgg0").eq($(this).index()).css("display", "block").attr("_block","block");
 })

 
 
 // cookie
 function setCookie(cname, cvalue, exdays) {
 		var d = new Date();
 		d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
 		var expires = "expires=" + d.toGMTString();
 		document.cookie = cname + "=" + cvalue + "; " + expires;
 	}
 
 	function getCookie(cname) {
 		var name = cname + "=";
 		var ca = document.cookie.split(';');
 		for (var i = 0; i < ca.length; i++) {
 			var c = ca[i].trim();
 			var arrC = c.split("=");
 			if (arrC[0] == cname) {
 				return arrC[1];
 			}
 		}
 		return "";
 	}
 
 
 	
 	$(".addCartButton").click(function(){
 		
 		var photo= $("[_block=block]").attr("src");
		
 		var name = $(".namee").text().trim();
		var nameen = $(".nameen").text().trim();
 		var price = $(".three").text().trim();
		var num = $(".num").text().trim();
		var clas = $("[_norm=norm]").children().text().trim();
 		var goods={
 			clas:clas,
 			name:name,
 			photo:photo,
 			price:price,
 			num:num,
			nameen:nameen,	
 			
 		}
 		
 		//读取cookie,原购物车数据
 		var cart = getCookie('cart')
 		if(cart){
 			var goodsList = JSON.parse(cart);
 			
 		}else{
 			var goodsList=[]
 		}
		var isExist = false;
			goodsList.forEach(function(item){
				if(item.clas==clas){
					isExist=true;
					item.num+num;
				}
			})
			if(!isExist){
				goodsList.push(goods)
			}
			
			
			
			//添加cookie
			setCookie('cart',JSON.stringify(goodsList))
		})